package cc.booku.owlbox.OrdinaryBooks_norm;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cc.booku.owlbox.OrdinaryVideo_norm.OrdinaryVideo_C;
import cc.booku.owlbox.R;

public class OrdinaryBooks_A extends BaseAdapter implements ListAdapter {


    private ArrayList<OrdinaryBooks_C> ordinaryBooks_cArrayList;
    private int id;
    private Context context;
    private LayoutInflater inflater;

    public OrdinaryBooks_A(int item, Context context, ArrayList<OrdinaryBooks_C> ordinaryBooks_cArrayList) {
        this.ordinaryBooks_cArrayList = ordinaryBooks_cArrayList;
        this.context = context;
        this.id = item;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return ordinaryBooks_cArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return ordinaryBooks_cArrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("WrongConstant")
    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {


        TextView vod_id = null;
        TextView vod_name = null;
        TextView vod_class = null;
        TextView vod_add_time = null;
        TextView vod_author = null;
        TextView vod_content = null;


        OrdinaryBooks_A.ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(id, null);

            vod_id = (TextView) view.findViewById(R.id.vod_id);
            vod_name = (TextView) view.findViewById(R.id.vod_name);
            vod_author = (TextView) view.findViewById(R.id.vod_author);
            vod_class = (TextView) view.findViewById(R.id.vod_class);
            vod_add_time = (TextView) view.findViewById(R.id.vod_add_time);
            vod_content = (TextView) view.findViewById(R.id.vod_content);


            view.setTag(new ViewHolder(vod_id, vod_name, vod_author, vod_class, vod_add_time, vod_content));
        } else {
            OrdinaryBooks_A.ViewHolder viewHolder1 = (OrdinaryBooks_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
            vod_id = viewHolder1.vod_id;
            vod_name = viewHolder1.vod_name;
            vod_author = viewHolder1.vod_author;
            vod_class = viewHolder1.vod_class;
            vod_add_time = viewHolder1.vod_add_time;
            vod_content = viewHolder1.vod_content;

        }
        OrdinaryBooks_C ordinaryBooksC = (OrdinaryBooks_C) ordinaryBooks_cArrayList.get(i); // 获取当前项的实例


        vod_id.setText(ordinaryBooksC.getVod_id().toString());
        vod_name.setText(ordinaryBooksC.getVod_name().toString());
        vod_author.setText(ordinaryBooksC.getVod_author().toString());
        vod_class.setText(ordinaryBooksC.getVod_class().toString());
        vod_add_time.setText(ordinaryBooksC.getVod_add_time().toString());
        vod_content.setText(ordinaryBooksC.getVod_content().toString());

        return view;

    }



    /*
     * vod_id,vod_name,vod_author,vod_class,vod_add_time,vod_content
     *
     * */

    private final class ViewHolder {
        TextView vod_id = null;
        TextView vod_name = null;
        TextView vod_author = null;
        TextView vod_class = null;
        TextView vod_add_time = null;
        TextView vod_content = null;


        public ViewHolder(TextView vod_id, TextView vod_name, TextView vod_author, TextView vod_class, TextView vod_add_time, TextView vod_content) {
            this.vod_class = vod_class;
            this.vod_id = vod_id;
            this.vod_name = vod_name;
            this.vod_author = vod_author;
            this.vod_add_time = vod_add_time;
            this.vod_content = vod_content;

        }

    }
}
